#include "stdafx.h"
#include "layout.h"
#include "Cell.h"
#include "SkCanvas.h"

Layout::Layout()
	: m_x(0)
	, m_y(0)
	, m_width(0)
	, m_height(0)
	, m_deno(0)
{
}


Layout::~Layout()
{
}

bool Layout::add(int index, View* view)
{
	int x = 0;
	for (std::list<Cell*>::iterator iter = m_cells.begin(); iter != m_cells.end(); ++iter, ++x)
	{
		if (x == index)
		{
			(*iter)->SetView(view);
			return true;
		}
	}
	
	return false;
}

bool Layout::add(int index, Layout* layout)
{
	int x = 0;
	for (std::list<Cell*>::iterator iter = m_cells.begin(); iter != m_cells.end(); ++iter, ++x)
	{
		if (x == index)
		{
			(*iter)->SetLayout(layout);
			return true;
		}
	}

	return false;
}

bool Layout::remove(int index)
{
	int x = 0;
	for (std::list<Cell*>::iterator iter = m_cells.begin(); iter != m_cells.end(); ++iter, ++x)
	{
		if (x == index)
		{
			m_cells.erase(iter);

			return true;
		}
	}

	return false;
}

bool Layout::onPaint(SkCanvas* pCanvas)
{
	for (std::list<Cell*>::iterator iter = m_cells.begin(); iter != m_cells.end(); ++iter)
	{
		if ((*iter) != NULL)
		{
			(*iter)->onPaint(pCanvas);
		}
	}

	return true;
}

void Layout::setRect(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
{
	m_x = x;
	m_y = y;
	m_width = width;
	m_height = height;
}

void Layout::getRect(unsigned int& x, unsigned int& y, unsigned int& width, unsigned int& height)
{
	x = m_x;
	y = m_y;
	width = m_width;
	height = m_height;
}